package com.eagle.functioninterface;

import org.junit.Test;

import java.util.function.*;

/**
 * 这类函数式接口的命名规则都是To+出参类型+Function
 * jdk8提供的有如下几个
 * {@link java.util.function.ToDoubleFunction}
 * {@link java.util.function.ToDoubleBiFunction}
 * {@link java.util.function.ToIntFunction}
 * {@link java.util.function.ToIntBiFunction}
 * {@link java.util.function.ToLongFunction}
 * {@link java.util.function.ToLongBiFunction}
 *
 * @author qinlinsen
 * @see java.util.function.Function
 */
public class ToFunctionTest13 {

    @Test
    public void testToDoubleBiFunction() {
        ToDoubleBiFunction<String, Double> f = (x, y) -> Double.valueOf(x) + y;
        final double result = f.applyAsDouble("3.2", 2d);
        System.out.println(result);
    }

    @Test
    public void testToDoubleFunction() {
        ToDoubleFunction<Integer> f = x -> x;
        final double result = f.applyAsDouble(3);
        System.out.println(result);
    }

    @Test
    public void testToIntBiFunction() {
        ToIntBiFunction<String, String> f = (x, y) -> Integer.valueOf(x) + Integer.valueOf(y);
        final int result = f.applyAsInt("3", "5");
        System.out.println(result);
    }

    @Test
    public void testToIntFunction() {
        ToIntFunction<String> f = x -> Integer.valueOf(x);
        int result = f.applyAsInt("3");
        System.out.println(result);
    }

    @Test
    public void testToLongFunction() {
        ToLongFunction<Integer> f = x -> x;
        final long result = f.applyAsLong(3);
        System.out.println(result);
    }

    @Test
    public void testToLongBiFunction() {
        ToLongBiFunction<String, String> f = (x, y) -> Long.valueOf(x) + Long.valueOf(y);

        final long result = f.applyAsLong("3", "5");
        System.out.println(result);

    }
}
